<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/8
 * Time: 13:46
 */
namespace app\blog\controller;
use cmf\controller\AdminBaseController;
use think\Db;

class FinanceController extends AdminBaseController
{
    //后台看流水   督导看自己管辖的店铺       总公司看所有
    public function added()
    {
        /**搜索条件**/
        $param = $this->request->param();
        $where=array();
        //$type=isset($param['type'])?$param['type']:'1';
        $starttime=isset($param['start_time'])?$param['start_time']:'';
        $endtime=isset($param['end_time'])?$param['end_time']:'';
        $storeid=isset($param['storeid'])?$param['storeid']:'';
        if(!empty($starttime) ) {
            $where['ctime'][]=array('egt',strtotime($starttime));
        }
        if(!empty($endtime) ) {
            $where['ctime'][]=array('lt',24*60*60+strtotime($endtime));
        }
        if(!empty($storeid) ) {
            $where['storeid']=$storeid;
        }
        //if($type==2){
        //    $where['money']=array('lt',0);
        //}else{
        //    $where['money']=array('gt',0);
        //}
        //判断登陆者权限(后期优化)
//         $uid=session('ADMIN_ID');
//         $uinfo=Db::name('User')->where(array('id'=>$uid))->find();
//         if($uinfo['user_type'] == 3){
//             $store_list=Db::name('Store')->where(array('steer'=>$uid))->field('id')->select()->toarray();
//             foreach($store_list as $k=>$v)
//             {
//                 $new_list[] = $v['id'];
//             }
//             $string=implode(',',$new_list);
//             $where['storeid']=array('in',$string);
//         }
        $mname=isset($param['mname'])?$param['mname']:'';
        $iddd='';
        if(!empty($mname)){
            $con['uname']=array('like',"%$mname%");
            $minfo=Db::name('Member')->where($con)->field('id')->select()->toarray();
            foreach ($minfo as $k=>$v){
                $ulist[]=$v['id'];
                $iddd.=','.$v['id'];
            }          
        }
       if(strlen($iddd)){
           $where['userid']=array('in',substr($iddd,1));
       }
       $orderNo=isset($param['orderNo'])?$param['orderNo']:'';
       if($orderNo){
           $where['orderid']=$orderNo;
       }
        $list=Db::name('FinanceRecord')->where($where)->order("id DESC")->paginate(10);
        //echo Db::name('FinanceRecord')->getlastsql();
        $list_store_list=Db::name('Store')->where(array('status'=>0))->select()->toarray();//正在运营的店铺列表
        // 获取分页显示
        $page = $list->render();
        //$xiaofei=array('1'=>'充值','2'=>'消费');
        $this->assign("list_store_list", $list_store_list);
        //$this->assign("xiaofei", $xiaofei);
        $this->assign("page", $page);
        $this->assign("list", $list);
        return $this->fetch();
    }    
}